
module.exports = class extends think.Controller {
  indexAction () { // 检查版本
    return this.display();
  }
  async getAction () { //获取日志
    const loglist = this.mongoose('mongoose/loglist');
    try {
      var result = await loglist.find({})
      this.json({
        status: 1,
        resulr: result
      })
    } catch (e) {
      this.json({
        status: -1,
        resulr: e.message
      })
    }
  }
  async clearAction () { // 清除日志
    const loglist = this.mongoose('mongoose/loglist');
    var result = await loglist.remove({})
    this.json(result)
  }
  async addAction () { // 添加日志
    try {
      const loglist = this.mongoose('mongoose/loglist');
      if (typeof this.post().result === 'string') {
        this.post().result = JSON.parse(this.post().result)
      }
      var data = new loglist({
        level: this.post().level || 'debug',
        type: this.post().type || '服务端',
        name: this.post().name,
        result: this.post().result
      })
      var result = await data.save()
      this.json({
        status: 1,
        resulr: result
      })
    } catch (e) {
      this.json({
        status: -1,
        resulr: e.message
      })
    }
  }
};